import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueDevTools from 'vite-plugin-vue-devtools'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const isProduction = mode === 'production'

  return {
    plugins: [vue(), VueDevTools()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      host: '0.0.0.0',
      proxy: isProduction || {
        '/api': {
          target: 'http://47.113.227.126:8001/dev-api/',
          changeOrigin: true,
          rewrite: (path) => {
            return path.replace(/\/api/, '')
          }
        }
      }
      // : {
      //     '/api': {
      //       target: 'http://47.113.227.126:8001/dev-api/',
      //       changeOrigin: true,
      //       rewrite: (path) => {
      //         return path.replace(/\/api/, '')
      //       }
      //     }
      //   }
    }
  }
})
